<?php

/**
 * client actions.
 *
 * @package    SdCommerce
 * @subpackage client
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class clientActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');
  }
  public function executeGetAllClient() {
        $clients= ClientTable::getInstance()->findAll();
        $response = array();
        if (count($clients) > 0) {
            foreach ($clients as $i => $pro) {
                $client = array();
                $client["id"] = $pro->getId();
                $client["raisonsociale"] = $pro->getRaisonSociale();

                $response["clients"][$i] = $client;
            }
            $response["success"] = 1;
        } else {
            $response["success"] = 0;
            $response["message"] = "No clients found";
        }

        return $this->renderText(json_encode($response));
    }
    public function executeCreateClient(sfWebRequest $request) {
        $response = array();
        $raisonsociale = $request->getParameter('raisonsociale');
        $telephone = $request->getParameter('telephone');
        $email = $request->getParameter('email');
        $fax = $request->getParameter('fax');
        $observation = $request->getParameter('observation');
        if ($raisonsociale != "" && $telephone != "" && $email != "" && $fax != "" && $observation != "") {
            $client = new Client();
            $client->setRaisonSociale($raisonsociale);
            $client->setTelephone1($telephone);
            $client->setEmail($email);
            $client->setFax($fax);
            $client->setObservation($observation);
            $client->save();
            $response['success'] = 1;
            $response['message'] = "Client ajouter avec succés.";
        } else {
            $response['success'] = 0;
            $response['message'] = "Oops! An error occurred.";
        }
        // echoing JSON response
        return $this->renderText(json_encode($response));
    }
    
}
